/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.pojo;

import java.sql.ResultSet;

import models.util.MySqlDataAccessHelper;

/**
 *
 * @author KimLien
 */

public class StIevoucherdetail  {
    private static final long serialVersionUID = 1L;
    
    
    private String iEVoucherDetailID;

	private String iEVoucherID;
    
    private String productID;
    private StProduct proInfo;
    
    private int unitID;
    private AcUnit unitInfo;
    
    private String storeID;
    private StStore storeInfo;
    
    private double quantity;
    
    private double price;
    
    private int taxID;
    private AcTax taxInfo;
    
    private int status;
    
    private double amount;
    
    private boolean selected;
    
    
   

	public boolean isSelected() {
		return selected;
	}

	public void setSelected(boolean selected) {
		this.selected = selected;
	}
    
    public String getiEVoucherDetailID() {
		return iEVoucherDetailID;
	}

	public void setiEVoucherDetailID(String iEVoucherDetailID) {
		this.iEVoucherDetailID = iEVoucherDetailID;
	}

	public StIevoucherdetail() {
    }

    public StIevoucherdetail(String iEVoucherDetailID) {
        this.iEVoucherDetailID = iEVoucherDetailID;
    }

    public StIevoucherdetail(String iEVoucherDetailID, String iEVoucherID,String productid,String storeid) {
        this.iEVoucherDetailID = iEVoucherDetailID;
        this.iEVoucherID = iEVoucherID;
        this.productID=productid;
        this.storeID=storeid;
    }
    public StIevoucherdetail(String iEVoucherDetailID, String iEVoucherID, String productID, int unitID, String storeID, int quantity, double price, int taxID, int status, double amount) {
        this.iEVoucherDetailID = iEVoucherDetailID;
        this.iEVoucherID = iEVoucherID;
        this.productID = productID;
        this.unitID = unitID;
        this.storeID = storeID;
        this.quantity = quantity;
        this.price = price;
        this.taxID = taxID;
        this.status = status;
        this.amount = amount;
    }

    public String getiEVoucherID() {
		return iEVoucherID;
	}

	public void setiEVoucherID(String iEVoucherID) {
		this.iEVoucherID = iEVoucherID;
	}

	public String getProductID() {
        return productID;
    }

    public void setProductID(String productID) {
        this.productID = productID;
    }

    public int getUnitID() {
        return unitID;
    }

    public void setUnitID(int unitID) {
        this.unitID = unitID;
    }

    public String getStoreID() {
        return storeID;
    }

    public void setStoreID(String storeID) {
        this.storeID = storeID;
    }

    public double getQuantity() {
        return quantity;
    }

    public void setQuantity(double quantity) {
        this.quantity = quantity;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getTaxID() {
        return taxID;
    }

    public void setTaxID(int taxID) {
        this.taxID = taxID;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public double getAmount() {
    	amount= price*quantity;
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

	public StProduct getProInfo() {
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		try {
			mysql.open();
			String sql="select * from st_product where ProductID='"+this.productID+"'";
			ResultSet rs = mysql.executeQuery(sql);
			if(rs.next()){
				proInfo=new StProduct();
				proInfo.setProductID(rs.getString("ProductID"));
				proInfo.setProductName(rs.getString("ProductName"));
				proInfo.setProTypeID(rs.getString("ProTypeID"));
				proInfo.setStoreID(rs.getString("StoreID"));
				proInfo.setManufacturerID(rs.getString("ManufacturerID"));
				proInfo.setProductName(rs.getString("ProductName"));
				proInfo.setUnitID(rs.getInt("UnitID"));
				proInfo.setTaxID(rs.getInt("TaxID"));
				proInfo.setOrigin(rs.getString("Origin"));
				proInfo.setInventoryMin(rs.getDouble("InventoryMin"));
				proInfo.setImage(rs.getString("Image"));
				proInfo.setPurchaseprice(rs.getDouble("Purchase_price"));
				proInfo.setRetailprice(rs.getDouble("Retail_price"));
				proInfo.setWholesale(rs.getDouble("Wholesale"));
				proInfo.setCurrencyID(rs.getInt("CurrencyID"));        		      		
				proInfo.setQuantity(rs.getInt("Quantity"));
				proInfo.setInventoryMax(rs.getDouble("InventoryMax"));
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			mysql.close();
		}

		return proInfo;
	}

	public void setProInfo(StProduct proInfo) {
		this.proInfo = proInfo;
	}

	public AcUnit getUnitInfo(String lang) {
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		
		try {
			mysql.open();
			String sql = "select * from ac_unit,ac_unit_lang where ac_unit.UnitID=ac_unit_lang.UnitID and ac_unit_lang.LangID='"+lang+"' and ac_unit.UnitID="+this.unitID;
			ResultSet rs = mysql.executeQuery(sql);
			while (rs.next()) {
				unitInfo = new AcUnit();
				unitInfo.setUnitId(rs.getInt("UnitID"));
				unitInfo.setUnitName(rs.getString("UnitName"));
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			mysql.close();
		}

		return unitInfo;
	}

	public void setUnitInfo(AcUnit unitInfo) {
		this.unitInfo = unitInfo;
	}

	public StStore getStoreInfo() {
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		try {
			mysql.open();
			String sql="select * from st_store where StoreID='"+this.getStoreID()+"'";
			ResultSet rs = mysql.executeQuery(sql);
			while(rs.next()){
				storeInfo=new StStore();
				storeInfo.setStoreID(rs.getString("StoreID"));
				storeInfo.setStoreName(rs.getString("Store_Name"));
			}
			rs.close();
		} catch (Exception e) {
			
		}finally{
			mysql.close();
		}
		return storeInfo;
	}

	public void setStoreInfo(StStore storeInfo) {
		this.storeInfo = storeInfo;
	}

	public AcTax getTaxInfo(String lang) {
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		
		try {
			mysql.open();
			String sql = "select * from ac_tax,ac_tax_lang " +
					"where ac_tax.TaxID=ac_tax_lang.TaxID " +
					"and ac_tax_lang.LangID='"+lang+"' " +
							"and ac_tax.TaxID="+this.taxID;
			ResultSet rs = mysql.executeQuery(sql);
			while (rs.next()) {
				taxInfo= new AcTax();
				taxInfo.setTaxId(rs.getInt("TaxID"));
				taxInfo.setTaxName(rs.getString("TaxName"));
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			mysql.close();
		}

		return taxInfo;
	}

	public void setTaxInfo(AcTax taxInfo) {
		this.taxInfo = taxInfo;
	}

    
    
}
